import random 
x4 = int(input('Введите четырёхзначное число: ')) 
max = 0 
if  x4> 9999 or x4 < 1000: 
    print ('0') 
def prost(n): 
    if n <= 1: 
        return False 
    for _ in range(5): 
        R = random.randint(1, n-1) 
        if pow(R, n-1, n) != 1: 
            return False 
        return True  


x1000= x4 // 1000 
if prost(x1000) == True: 
    max = x1000#1 


x100= x4 // 100 
if prost(x100)== True and x100 > max: 
    max =x100#2 


x10 = x4//10
if prost(x10) == True and x10 > max: 
    max =x10#3 


z= x4 
if prost(z) == True and z > max: 
    max =z#4 


x = x4 // 100 % 10 
if prost(x) == True and x > max: 
    max = x#5 


o = x4 // 10 % 100 
if prost(o) == True and sd > max: 
    max =o#6 


f = x4 % 1000 
if prost(f) == True and sde > max: 
    max = f#7 


zv = x4 // 10 %10 
if prost(zv) == True and zv > max: 
    max = zv#8 


g = x4 % 100 
if prost(g) == True and g > max: 
    max = g#9 


k = x4 % 10 
if prost(k) == True and k > max: 
    max = k#10 


print(max)